var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/user-list', function (req, res, next) {
  // res.render('index', { title: 'Express' });
  var db = req.db;
  var collection = db.get("food");
  collection.find({}, {}, function (err, doc) {
    res.send({
      "userlist": doc
    })
  })
});

router.post('/addUser', function (req, res, next) {
  var db = req.db
  var collection = db.get('user')
  var name = req.body.name
  var email = req.body.email
  collection.insert({ 'name': name, 'email': email }, function (err, doc) {
    if (err) {
      console.log(err)
    } else {
      res.send('数据插入成功')
    }
  })
})

router.get('/', function (req, res, next) {
  res.send('user')
})

module.exports = router;
